package itheima.zuoye.Test6;

import java.util.Arrays;
import java.util.Comparator;

//将数组中的学生按照年纪升序排序，如果年龄一样就按成绩降序排序
public class Test {
    public static void main(String[] args) {
        Student[] students = {
                new Student("张三", 20, "男", 175.5, 88.5),
                new Student("李四", 19, "女", 163.2, 92.0),
                new Student("王五", 21, "男", 180.0, 85.5),
                new Student("赵六", 20, "女", 168.8, 90.5),
                new Student("钱七", 21, "男", 172.3, 100.0),
        };
        Arrays.sort(students, (o1, o2) -> {
            int result = o1.getAge() - o2.getAge();
            if (result == 0) {
                result = (int) (o2.getScores() - o1.getScores());
            }
            return result;
        });
        System.out.println(Arrays.toString(students));

    }
}
